<?php

use Illuminate\Support\Facades\Redirect;
class PluginController extends BaseController { 

	public function botsearch(){
		$se = Input::get('desc');
		$api = Input::get('api');
		$charname = Input::get('ch');
		$code = Input::get('code');

		if(!($api == 'Y2FkZWF0aA==')) die();

		$search = Search::where('accesscode','=',$code)
					->where('notUsed','=',false)
					->first();
		if(!(count($search)>0)) {
			echo "Item not found";
			die();
		}

		$search->charname = $charname;
		$search->keyword = $se;
		$search->notUsed = true;
		$search->save();

		$date = date("Y-m-d H:i:s");
		$items = Item::where('item', 'LIKE', '%' . $se . '%')
			->whereRaw('DATE_ADD(created_at, INTERVAL 24 HOUR) > NOW()')
			->get();

		foreach ($items as $key => $item) {
			echo $key + 1 . ". " . $item->item . "|charname: " . $item->charname . "|cost: " . $item->price . "|loc: " . $item->location . "\n";
		}
	}

}